<?php

namespace App\Http\Controllers\API;

use App\Models\Cafe;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class CafesController extends Controller
{
    //
    public function getCafes()
    {
        $cafes = Cafe::all();
        return response()->json($cafes);

    }

    public function getCafe($id)
    {
        $cafe = Cafe::where('id', '=', $id)->first();
        return response()->json($cafe);
    }


    public function postNewCafe()
    {
        $cafe = new Cafe();

        $cafe->name     = Request::get('name');
        $cafe->address  = Request::get('address');
        $cafe->city     = Request::get('city');
        $cafe->state    = Request::get('state');
        $cafe->zip      = Request::get('zip');

        $cafe->save();

        return response()->json($cafe, 201);

    }


}
